package cn.school.common.wx;

import cn.school.common.utils.HttpClientUtil;
import com.google.gson.JsonObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class WechatUtils {
    private  String appid_web;

    private  String app_secret_web;

    private String wx_appId_codeUrl;

    public JsonObject getSessionKeyOrOpenId(String code) throws Exception {
        Map<String, String> requestUrlParam = new HashMap<String, String>();
        String wechatSmallAppid = appid_web;
        String wechatSmallSecret = app_secret_web;
//		if(!StringUtils.isEmpty(redisUtil.get("WXPayConfig"))){
//			Map<String,String> wxPay = (Map<String,String>)redisUtil.get("WXPayConfig");
//			wechatSmallAppid = wxPay.get("wechatSmallAppid");
//			wechatSmallSecret = wxPay.get("wechatSmallSecret");
//		}

        requestUrlParam.put("appid", wechatSmallAppid);// 小程序appId
        requestUrlParam.put("secret", wechatSmallSecret);
        requestUrlParam.put("js_code", code);// 小程序端返回的code
        requestUrlParam.put("grant_type", "authorization_code");// 默认参数
        return HttpClientUtil.httpGetGo(wx_appId_codeUrl, requestUrlParam);
    }
}
